package com.lijin.workshop.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.log4j.Logger;

import com.lijin.workshop.cache.CacheManager;
import com.lijin.workshop.constants.SysConstants;
import com.lijin.workshop.util.StringUtil;

public class OnStartupServlet extends HttpServlet {

	private static final Logger logger = Logger.getLogger(OnStartupServlet.class);
	
	private static final long serialVersionUID = 1L;

	@Override
	public void init() throws ServletException {
		super.init();
		
		logger.info("----系统初始化开始----");

		// 如果系统启动时指定了配置文件的路径，
		// 则将该路径信息保存在常量类的SYS_CONFIG_PATH_PARAM字段中
		String configDir = System.getProperty(SysConstants.CONFIG_PATH_PARAM);
		if (!StringUtil.isBlank(configDir)) {
			logger.info("系统配置文件路径--->" + configDir);
			SysConstants.CONFIG_PATH = configDir;
		}
		
		// 初始化缓存
		CacheManager.initCaches();
		
		logger.info("----系统初始化完成----");
	}
	
}
